package com.test.model
{
  import com.test.UserVO;
  import mx.utils.ObjectUtil;

  [Bindable]
  public class User
  {

    /**
     * private instance of a User Value Object
     */
    private var vo:UserVO = new UserVO();

    /**
     * Bindable accessor methods to enforce business logic
     */
    public function set id(value:int):void { vo.id = value;}
    public function get id():int { return vo.id;}
    public function set name(value:String):void { vo.name = value;}
    public function get name():String { return vo.name;}
    public function set count(value:int):void { vo.count = value;}
    public function get count():int { return vo.count;}
    public function set weight(value:Number):void { vo.weight = value;}
    public function get weight():Number { return vo.weight;}
    public function set married(value:Boolean):void { vo.married = value;}
    public function get married():Boolean { return vo.married;}

    /**
     * Return a new UserVO instance from the private instance vo
     */
    public function toVO():UserVO
    {
      var newVo:UserVO = new UserVO();
      var oldVo:Object = ObjectUtil.copy(vo);
      for (var property:String in oldVo){
        newVo[property] = oldVo[property];
      }
      return newVo;
    }

    /**
     * Return a User instance with values from a UserVO instance
     */
    public static function fromVO(vo:UserVO):User
    {
      var newMo:User = new User();
      var oldVo:Object = ObjectUtil.copy(vo);
      for (var property:String in oldVo) {
        newMo[property] = oldVo[property];
      }
      return newMo;
    }
  }
}
